function p=boltztest()
% test boltzman approximation by polynomial for first 3 terms of the taylor series expansion
%
n = 5;
x=-100:5:0;
k=5;
I=1;
x0=-50;
b = I./(1+exp(-(x-x0)/k));
r = fminsearch('boltz', x, [], 1, 1, 1)



return;
% nothing after here executes...
a1=min(x);
a2=max(x);
l = length(x);
sf = 1;
xf=x/sf;
p = polyfit(xf,b,n);
y = polyval(p,xf);
clf;
plot(xf,b,'rx');
hold on;
plot(xf,y,'-b');
%
% now do the taylor series recovery... and print the values for comparison.
k1 = -p(n)^2+p(n+1)*p(n-1);
k2 = k1+p(n+1)*p(n-1);
k0 = -0.5*p(n)*p(n+1);
Inew = 2*p(n+1)*k1/k2;
x0new = k0*log(-p(n)^2/k2)/k1;
knew = k0/k1;
disp(sprintf('I: %8.3f Inew: %8.3f\nx0: %8.3f  x0new: %8.3f\n k: %8.3f  knew: %8.3f',...
   I, Inew, x0, x0new*sf, k, knew*sf))

q=exp(x0/k);
v=(1+exp(x0/k));
p0=I/v;
p1=(q/k)*(I/v^2);
p2=(-0.5*(q/k^2)*(I/v)+(I/v^2)*q^2/k^2)/v;
disp(sprintf('P0: %8.3f  p(n+1): %8.3f', p0, p(n+1)))
disp(sprintf('P1: %8.3f  p(n): %8.3f', p1, p(n)))
disp(sprintf('P2: %8.3f  p(n-1): %8.3f', p2, p(n-1)))


